/*
多态: 多种形态
*/
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
(function () {
    var Animal = /** @class */ (function () {
        function Animal(name) {
            this.name = name;
        }
        Animal.prototype.run = function (distance) {
            if (distance === void 0) { distance = 0; }
            console.log(this.name + " run " + distance + "m");
        };
        return Animal;
    }());
    var Snake = /** @class */ (function (_super) {
        __extends(Snake, _super);
        function Snake(name) {
            // 调用父类型构造方法
            return _super.call(this, name) || this;
        }
        // 重写父类型的方法
        Snake.prototype.run = function (distance) {
            if (distance === void 0) { distance = 5; }
            console.log('sliding...');
            _super.prototype.run.call(this, distance);
        };
        return Snake;
    }(Animal));
    var Horse = /** @class */ (function (_super) {
        __extends(Horse, _super);
        function Horse(name) {
            // 调用父类型构造方法
            return _super.call(this, name) || this;
        }
        // 重写父类型的方法
        Horse.prototype.run = function (distance) {
            if (distance === void 0) { distance = 50; }
            console.log('dashing...');
            // 调用父类型的一般方法
            _super.prototype.run.call(this, distance);
        };
        Horse.prototype.xxx = function () {
            console.log('xxx()');
        };
        return Horse;
    }(Animal));
    var a1 = new Animal('a1');
    var a2 = new Snake('s1'); // 父类型引用指向子类型对象
    var a3 = new Horse('h1'); // 父类型引用指向子类型对象
    function fn(a) {
        a.run();
    }
    fn(a1);
    fn(new Snake('s1')); // 内部调用的是snake的run方法
    fn(new Horse('h1')); // 内部调用的是horse的run方法
})();
